package com.okilo.online.app.pet

import com.okilo.online.app.common.OkiloComPet
import com.okilo.online.app.request.HttpHelper
import com.okilo.online.app.request.IHttpCallback
import com.okilo.online.app.pet.view.IOkiloUpload
import org.json.JSONObject

/**
 * 文件上传
 */
class OkiloUploadPet(private val iView: IOkiloUpload?): OkiloComPet(iView) {

    /**
     * 文件上传
     * /v1/imageUpload
     */
    fun uploadOkiloFileRequest(filePath: String){
        HttpHelper.upload(filePath,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val obj = data.optJSONObject("obj")
                obj?.let {
                    val imgUrl = it.optString("url")
                    iView?.sOkiloUploadFileSuccess(filePath,imgUrl)
                }
            }
            override fun onRequestError(error: JSONObject) {
                iView?.showOkiloToast(error.optString("errorMsg"))
            }

            override fun onRequestFinish() {
                iView?.hideOkiloLoading()
            }
        })
    }
}